package com.landeb.shop.huo.act;

import android.os.Bundle;
import android.util.Log;

import com.landeb.shop.R;

import java.util.concurrent.TimeUnit;

import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class SplashActivity extends BaseActivity {

    private int mTimeCount;
    private Subscription mTimer;
    /**跳转时间*/
    int jumpTime = 1;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        jumpToMainAct();

    }

    private void jumpToMainAct() {

        mTimeCount = 0;
        mTimer = rx.Observable.interval(1, TimeUnit.SECONDS)
                .subscribeOn(Schedulers.computation())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<Long>() {
                    @Override
                    public void onCompleted() {
                        Log.e("BtnTimer", "onCompleted:xxxxxxxxxxxxxx ");
                    }

                    @Override
                    public void onError(Throwable e) {

                        Log.e("BtnTimer", "onError:xxxxxxxxxxxxxx ");


                    }

                    @Override
                    public void onNext(Long aLong) {
                        mTimeCount++;

                        if (mTimeCount == jumpTime) {

                            MainActivity.toAct(SplashActivity.this, 0);

                            finish();
                        }

                    }


                });

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        if (mTimer.isUnsubscribed()) {
            mTimer.unsubscribe();
        }
    }
}
